//
//  SetTableViewCell.swift
//  fruit-helper-swift
//
//  Created by 赵隆杰 on 2022/6/25.
//

import UIKit

class SetTableViewCell: UITableViewCell {

    var cellImage: UIImageView!
    var cellTitle : UILabel!
//    private var cellTime : UILabel!
    private var cellLine : UILabel!
    
    var model: BookModel? {
        didSet {
            if let imageStr = model?.imageStr {
                cellImage.image = UIImage(named: imageStr)
            }
            cellTitle.text = "\(model?.book_title ?? "")"
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        cellImage = UIImageView()
        cellImage.layer.cornerRadius = 5
        cellImage.layer.masksToBounds = true
        cellImage.contentMode = .scaleAspectFill
        self.addSubview(cellImage)
        cellImage.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(10)
            make.left.equalToSuperview().offset(20)
            make.centerY.equalToSuperview()
            make.width.equalTo(cellImage.snp.height)
        }
        
        cellTitle = UILabel()
        self.addSubview(cellTitle)
        cellTitle.snp.makeConstraints { make in
            make.left.equalTo(cellImage.snp.right).offset(20)
            make.right.equalToSuperview().offset(-10)
            make.top.equalTo(cellImage).offset(5)
        }
        
//        cellTime = UILabel()
//        self.addSubview(cellTime)
//        cellTime.snp.makeConstraints { make in
//            make.left.equalTo(cellTitle)
//            make.top.equalTo(cellTitle.snp.bottom).offset(10)
//        }
        
        cellLine = UILabel()
        cellLine.backgroundColor = kLineColor
        self.addSubview(cellLine)
        cellLine.snp.makeConstraints { make in
            make.left.equalTo(cellImage)
            make.bottom.right.equalToSuperview()
            make.height.equalTo(1)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
